namespace DotNetNuke.UI.UserControls
{
    using DotNetNuke.Framework;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI.WebControls;

    public class DualListControl : UserControlBase
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        private ArrayList _Assigned;
        private ArrayList _Available;
        //("cmdAdd")]
        private LinkButton _cmdAdd;
        //("cmdAddAll")]
        private LinkButton _cmdAddAll;
        //("cmdRemove")]
        private LinkButton _cmdRemove;
        //("cmdRemoveAll")]
        private LinkButton _cmdRemoveAll;
        private string _DataTextField;
        private string _DataValueField;
        private bool _Enabled;
        private string _ListBoxHeight;
        private string _ListBoxWidth;
        //("lstAssigned")]
        private ListBox _lstAssigned;
        //("lstAvailable")]
        private ListBox _lstAvailable;
        protected Label Label1;
        protected Label Label2;
        private string MyFileName;

        public DualListControl()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this._ListBoxWidth = "";
            this._ListBoxHeight = "";
            this._DataTextField = "";
            this._DataValueField = "";
            this._Enabled = true;
            this.MyFileName = "DualListControl.ascx";
        }

        private void cmdAdd_Click(object sender, EventArgs e)
        {
            ListItem objListItem=null;
            IEnumerator refObjectHelperL0=null;
            IEnumerator refObjectHelperL1=null;
            ArrayList objList = new ArrayList();
            try
            {
                refObjectHelperL0 = this.lstAvailable.Items.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL0.Current;
                    objList.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            try
            {
                refObjectHelperL1 = objList.GetEnumerator();
                while (refObjectHelperL1.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL1.Current;
                    if (objListItem.Selected)
                    {
                        this.lstAvailable.Items.Remove(objListItem);
                        this.lstAssigned.Items.Add(objListItem);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL1 is IDisposable)
                {
                    (refObjectHelperL1 as IDisposable).Dispose();
                }
            }
            this.lstAvailable.ClearSelection();
            this.lstAssigned.ClearSelection();
            this.Sort(this.lstAssigned);
        }

        private void cmdAddAll_Click(object sender, EventArgs e)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = this.lstAvailable.Items.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    ListItem objListItem = (ListItem) refObjectHelperL0.Current;
                    this.lstAssigned.Items.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            this.lstAvailable.Items.Clear();
            this.lstAvailable.ClearSelection();
            this.lstAssigned.ClearSelection();
            this.Sort(this.lstAssigned);
        }

        private void cmdRemove_Click(object sender, EventArgs e)
        {
            ListItem objListItem=null;
            IEnumerator refObjectHelperL0=null;
            IEnumerator refObjectHelperL1=null;
            ArrayList objList = new ArrayList();
            try
            {
                refObjectHelperL0 = this.lstAssigned.Items.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL0.Current;
                    objList.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            try
            {
                refObjectHelperL1 = objList.GetEnumerator();
                while (refObjectHelperL1.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL1.Current;
                    if (objListItem.Selected)
                    {
                        this.lstAssigned.Items.Remove(objListItem);
                        this.lstAvailable.Items.Add(objListItem);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL1 is IDisposable)
                {
                    (refObjectHelperL1 as IDisposable).Dispose();
                }
            }
            this.lstAvailable.ClearSelection();
            this.lstAssigned.ClearSelection();
            this.Sort(this.lstAvailable);
        }

        private void cmdRemoveAll_Click(object sender, EventArgs e)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = this.lstAssigned.Items.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    ListItem objListItem = (ListItem) refObjectHelperL0.Current;
                    this.lstAvailable.Items.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            this.lstAssigned.Items.Clear();
            this.lstAvailable.ClearSelection();
            this.lstAssigned.ClearSelection();
            this.Sort(this.lstAvailable);
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.Label1.Text = DotNetNuke.Services.Localization.Localization.GetString("Available", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                this.Label2.Text = DotNetNuke.Services.Localization.Localization.GetString("Assigned", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                this.cmdAdd.ToolTip = DotNetNuke.Services.Localization.Localization.GetString("Add", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                this.cmdAddAll.ToolTip = DotNetNuke.Services.Localization.Localization.GetString("AddAll", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                this.cmdRemove.ToolTip = DotNetNuke.Services.Localization.Localization.GetString("Remove", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                this.cmdRemoveAll.ToolTip = DotNetNuke.Services.Localization.Localization.GetString("RemoveAll", DotNetNuke.Services.Localization.Localization.GetResourceFile(this, this.MyFileName));
                if (!this.Page.IsPostBack)
                {
                    if (this._ListBoxWidth != "")
                    {
                        this.lstAvailable.Width = Unit.Parse(this._ListBoxWidth);
                        this.lstAssigned.Width = Unit.Parse(this._ListBoxWidth);
                    }
                    if (this._ListBoxHeight != "")
                    {
                        this.lstAvailable.Height = Unit.Parse(this._ListBoxHeight);
                        this.lstAssigned.Height = Unit.Parse(this._ListBoxHeight);
                    }
                    this.lstAvailable.DataTextField = this._DataTextField;
                    this.lstAvailable.DataValueField = this._DataValueField;
                    this.lstAvailable.DataSource = this._Available;
                    this.lstAvailable.DataBind();
                    this.Sort(this.lstAvailable);
                    this.lstAssigned.DataTextField = this._DataTextField;
                    this.lstAssigned.DataValueField = this._DataValueField;
                    this.lstAssigned.DataSource = this._Assigned;
                    this.lstAssigned.DataBind();
                    this.Sort(this.lstAssigned);
                    this.lstAvailable.Enabled = this._Enabled;
                    this.lstAssigned.Enabled = this._Enabled;
                    this.ViewState[this.ClientID + "_ListBoxWidth"] = this._ListBoxWidth;
                    this.ViewState[this.ClientID + "_ListBoxHeight"] = this._ListBoxHeight;
                }
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
                
            }
        }

        private void Sort(ListBox ctlListBox)
        {
            ListItem objListItem=null;
            IEnumerator refObjectHelperL0=null;
            IEnumerator refObjectHelperL1=null;
            ArrayList arrListItems = new ArrayList();
            try
            {
                refObjectHelperL0 = ctlListBox.Items.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL0.Current;
                    arrListItems.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            arrListItems.Sort(new ListItemComparer());
            ctlListBox.Items.Clear();
            try
            {
                refObjectHelperL1 = arrListItems.GetEnumerator();
                while (refObjectHelperL1.MoveNext())
                {
                    objListItem = (ListItem) refObjectHelperL1.Current;
                    ctlListBox.Items.Add(objListItem);
                }
            }
            finally
            {
                if (refObjectHelperL1 is IDisposable)
                {
                    (refObjectHelperL1 as IDisposable).Dispose();
                }
            }
        }

        public ArrayList Assigned
        {
            get
            {
                IEnumerator refObjectHelperL0=null;
                ArrayList objList = new ArrayList();
                try
                {
                    refObjectHelperL0 = this.lstAssigned.Items.GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        ListItem objListItem = (ListItem) refObjectHelperL0.Current;
                        objList.Add(objListItem);
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
                return objList;
            }
            set
            {
                this._Assigned = value;
            }
        }

        public ArrayList Available
        {
            get
            {
                IEnumerator refObjectHelperL0=null;
                ArrayList objList = new ArrayList();
                try
                {
                    refObjectHelperL0 = this.lstAvailable.Items.GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        ListItem objListItem = (ListItem) refObjectHelperL0.Current;
                        objList.Add(objListItem);
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
                return objList;
            }
            set
            {
                this._Available = value;
            }
        }

        protected virtual LinkButton cmdAdd
        {
           
            get
            {
                return this._cmdAdd;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdAdd_Click);
                if (this._cmdAdd != null)
                {
                    this._cmdAdd.Click -= handler;
                }
                this._cmdAdd = value;
                if (this._cmdAdd != null)
                {
                    this._cmdAdd.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdAddAll
        {
           
            get
            {
                return this._cmdAddAll;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdAddAll_Click);
                if (this._cmdAddAll != null)
                {
                    this._cmdAddAll.Click -= handler;
                }
                this._cmdAddAll = value;
                if (this._cmdAddAll != null)
                {
                    this._cmdAddAll.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdRemove
        {
           
            get
            {
                return this._cmdRemove;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdRemove_Click);
                if (this._cmdRemove != null)
                {
                    this._cmdRemove.Click -= handler;
                }
                this._cmdRemove = value;
                if (this._cmdRemove != null)
                {
                    this._cmdRemove.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdRemoveAll
        {
           
            get
            {
                return this._cmdRemoveAll;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdRemoveAll_Click);
                if (this._cmdRemoveAll != null)
                {
                    this._cmdRemoveAll.Click -= handler;
                }
                this._cmdRemoveAll = value;
                if (this._cmdRemoveAll != null)
                {
                    this._cmdRemoveAll.Click += handler;
                }
            }
        }

        public string DataTextField
        {
            set
            {
                this._DataTextField = value;
            }
        }

        public string DataValueField
        {
            set
            {
                this._DataValueField = value;
            }
        }

        public bool Enabled
        {
            set
            {
                this._Enabled = value;
            }
        }

        public string ListBoxHeight
        {
            get
            {
                return Convert.ToString(RuntimeHelpers.GetObjectValue(this.ViewState[this.ClientID + "_ListBoxHeight"]));
            }
            set
            {
                this._ListBoxHeight = value;
            }
        }

        public string ListBoxWidth
        {
            get
            {
                return Convert.ToString(RuntimeHelpers.GetObjectValue(this.ViewState[this.ClientID + "_ListBoxWidth"]));
            }
            set
            {
                this._ListBoxWidth = value;
            }
        }

        protected virtual ListBox lstAssigned
        {
           
            get
            {
                return this._lstAssigned;
            }
            
            set
            {
                this._lstAssigned = value;
            }
        }

        protected virtual ListBox lstAvailable
        {
           
            get
            {
                return this._lstAvailable;
            }
            
            set
            {
                this._lstAvailable = value;
            }
        }
    }
}

